<?php

class Wlib_Controller_Plugin_MultiLayout extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $moduleName = $request->getModuleName();
        $mvcInstance = Zend_Layout::getMvcInstance();
        $layoutFile = $mvcInstance->getLayoutPath(). DIRECTORY_SEPARATOR . $moduleName.'.phtml';
        if (file_exists($layoutFile)) {
            $mvcInstance->setLayout($moduleName);
        } else {
            $mvcInstance->setLayout('layout');
        }
        parent::preDispatch($request);
    }

}

?>